﻿using Iworld.Backstage.Framework;
using Iworld.Backstage.Framework.AdministratorService;
using Iworld.Backstage.Framework.AuthorService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Backstage
{
    public partial class ChangeWithdrawalsStatusWindow : ChildWindow
    {
        public ChangeWithdrawalsStatusWindow()
        {
            InitializeComponent();
        }

        public WithdrawalsRecordExport Info
        {
            get { return (WithdrawalsRecordExport)GetValue(InfoProperty); }
            set { SetValue(InfoProperty, value); }
        }

        public static readonly DependencyProperty InfoProperty =
            DependencyProperty.Register("Info", typeof(WithdrawalsRecordExport), typeof(ChangeWithdrawalsStatusWindow), new PropertyMetadata(null, (s, args) => { }));


        void Request(WithdrawalsStatus newStatus)
        {
            AuthorServiceClient client = new AuthorServiceClient();
            client.ChangeWithdrawalsStatusCompleted += (se, arg) =>
            {
                if (arg.Result.Success)
                {
                    new ErrorPrompt() { Info = "操作成功" }.Show();
                    this.DialogResult = true;
                }
                else
                {
                    new ErrorPrompt() { Info = arg.Result.Error }.Show();
                }
            };
            client.ChangeWithdrawalsStatusAsync(new ChangeWithdrawalsStatusImport()
            {
                Remark = UIRemark.Text,
                WithdrawalsId = Info.Id,
                NewStatus = newStatus,
                Token = DataManager.GetValue<AdministratorExport>(DataKey.Administrator_Info).Token
            });
        }

        private void Yes(object sender, RoutedEventArgs e)
        {

            ConfirmPrompt cp = new ConfirmPrompt() { Info = "确定通过提现申请吗?" };
            cp.Closed += (s, args) => { 
               if(cp.DialogResult == true)
               {

                   Request(WithdrawalsStatus.提现成功);
                     
               }
            
            };
            cp.Show();

        }

        private void No(object sender, RoutedEventArgs e)
        {
            ConfirmPrompt cp = new ConfirmPrompt() { Info = "确定否决提现申请吗?" };
            cp.Closed += (s, args) =>
            {
                if (cp.DialogResult == true)
                {
                    Request(WithdrawalsStatus.失败);
                }

            };
            cp.Show();
        }

        private void Cancel(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        
    }
}

